package com.sinodata.bsm.center.web.action.test;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.googlecode.jsonplugin.annotations.JSON;
import com.sinodata.bsm.center.service.probe.CollectTestService;
import com.sinodata.bsm.center.web.action.BaseAction;
import com.sinodata.bsm.common.vo.ResPropertyValue;

import flexjson.JSONSerializer;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-17 下午1:18:27          liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class CollectTestAction<T> extends BaseAction<Object> {

    /**
     * 
     */
    private static final long serialVersionUID = 4555557972944482851L;

    private Long probeId;

    private String collectorName;

    private String resIp;

    @Autowired
    private CollectTestService collectTestService;

    @JSON(serialize = false)
    public String getCollectorParamMeta() {
        String[] p = collectTestService.getCollectorParamMeta(probeId, collectorName);
        JSONSerializer s = new JSONSerializer();
        String result = s.deepSerialize(p);
        renderText(result);
        return null;
    }

    public String collect() {
        Map<String, String> params = new HashMap<String, String>();
        String[] p = collectTestService.getCollectorParamMeta(probeId, collectorName);
        for (int i = 0; i < p.length; i++) {
            params.put(p[i], request.getParameter(p[i]));
        }
        List<ResPropertyValue> list = collectTestService.collect(probeId, collectorName, params, resIp);
        for (ResPropertyValue v : list) {
            System.out.println(v);
        }
        return null;

    }

    /*
     * (non-Javadoc)
     * @see com.opensymphony.xwork2.ModelDriven#getModel()
     */
    @Override
    public Object getModel() {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.web.action.BaseAction#list()
     */
    @Override
    public String list() throws Exception {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.web.action.BaseAction#input()
     */
    @Override
    public String input() throws Exception {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.web.action.BaseAction#save()
     */
    @Override
    public String save() throws Exception {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.web.action.BaseAction#delete()
     */
    @Override
    public String delete() throws Exception {
        return null;
    }

    /* (non-Javadoc)
     * @see com.sinodata.bsm.center.web.action.BaseAction#prepareModel()
     */
    @Override
    protected void prepareModel() throws Exception {

    }

    public Long getProbeId() {
        return probeId;
    }

    public void setProbeId(Long probeId) {
        this.probeId = probeId;
    }

    public String getCollectorName() {
        return collectorName;
    }

    public void setCollectorName(String collectorName) {
        this.collectorName = collectorName;
    }

    public String getResIp() {
        return resIp;
    }

    public void setResIp(String resIp) {
        this.resIp = resIp;
    }

}
